package com.unreal.resourcemanager.utils;

import java.math.BigDecimal;

/**
 * @Author: unreal
 * @Date: 2021-03-20 16:03
 * @Description:
 */
public class Circulate {
    public static final char[] UNIT = {'B','K','M','G','T'};
    public static final BigDecimal SCALE = BigDecimal.valueOf(1024L);

    public static String getFileSize(long size){
        int index = 0;
        BigDecimal val = BigDecimal.valueOf(size);
        while (val.compareTo(SCALE) != -1){
            val = val.divide(SCALE).setScale(1,BigDecimal.ROUND_HALF_UP);
            index ++;
        }
        return val.toString() + UNIT[index];
    }
}
